package com.example.higo.view.adapter;

import android.graphics.drawable.Drawable;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;


/**
 * Created by wj on 2016/10/15.
 */

public class MyBaseViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
    public MyBaseViewHolder(View itemView) {
        super(itemView);
        itemView.setOnClickListener(this);
    }

    /**
     * setText方法
     */
    public MyBaseViewHolder setText(int resId, String text) {
        TextView textView = (TextView) itemView.findViewById(resId);
        textView.setText(text);
        return this;
    }

    /**
     * setImg方法
     */
    public MyBaseViewHolder setImg(int resId, String path) {
//        ImageView imageView = (ImageView) itemView.findViewById(resId);
//        Glide.with(itemView.getContext())
//                .load(path)
//                .fitCenter()
//                .placeholder(android.R.drawable.bottom_bar)
//                .error(android.R.drawable.bottom_bar)
//                .into(imageView);
        SimpleDraweeView simpleDraweeView = (SimpleDraweeView) itemView.findViewById(resId);
        simpleDraweeView.setImageURI(path);
        return this;
    }


    public MyBaseViewHolder setImg(int resId, int redId) {
        ImageView imageView = (ImageView) itemView.findViewById(resId);
        imageView.setImageResource(redId);
        return this;
    }

    public MyBaseViewHolder setImg(int resId, Drawable redId) {
        ImageView imageView = (ImageView) itemView.findViewById(resId);
        imageView.setImageDrawable(redId);
        return this;
    }

    /**
     * convertView 方法 得到View 去 findViewById
     *
     * @return
     */
    public View convertView() {
        return itemView;
    }

    OnItemClickListener o;
    @Override
    public void onClick(View v) {
        if(o!=null){
            o.onClick(v);
        }
    }

    public interface OnItemClickListener{
        void onClick(View v);
    }
}
